indexers in python

46

class my_data:
  
	def __init__(self):
  		self.data = [0,1,2]
        
	def __getitem__(self, index):
    	return self.data[index]

	def __setitem__(self, index, value):
    	self.data[index] = value
        
custom_data = my_data()
custom_data[0] = "my_value"
print(custom_data[0])

Comments

Submit
0 Comments